package com.rt.easyjava.base.biz1.controller;

import com.rt.easyjava.base.biz1.controller.base.TmptBaseFileController;
import com.rt.easyjava.base.biz1.dto.TmptBaseFileBizDto;
import com.rt.easyjava.common.base.Result;
import com.rt.easyjava.common.base.UserDetailsDto;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * 前端控制器
 * 1，自定义代码：源码生成器，创建模板，第一次生成源码时，会自动创建此类，之后生成源码时，此类将不做修改处理；
 *    所以，程序员应该在这个类里写自己的代码，后续需求变更，自动生成源码时，不影响此类。
 * 2，用户信息可直接形参获取：String (_userId，_loginName，_userName，_companyId，_userJson) or userDetailsDto.getUserId()
 * @author wuxiaoyong
 * @since 2020-11-18
 */
@Slf4j
@Api(tags = "TmptBaseFileBizController -  控制类")
@RequestMapping("/coding/tmptBaseFile")
@Controller
public class TmptBaseFileBizController extends TmptBaseFileController {
    @PreAuthorize("hasAuthority('tmptBaseFile:query')")
    @ApiOperation("分页查询列表（适合单表查询）")
    @GetMapping(value = "/page")
    @ResponseBody
    public Result page(@ModelAttribute TmptBaseFileBizDto tmptBaseFileBizDto, String userDetailsJson){
        UserDetailsDto userDetailsDto = UserDetailsDto.getUserDetailsDto(userDetailsJson, "tmptBaseFile:query");
        return super.page(tmptBaseFileBizDto, userDetailsDto);
    }


    @PreAuthorize("hasAuthority('tmptBaseFile:query')")
    @ApiOperation("以ID作为父节点，查询子树")
    @GetMapping(value = "/tree")
    @ResponseBody
    public Result tree (Long id) {
        return super.tree(id);
    }

    @PreAuthorize("hasAuthority('tmptBaseFile:query')")
    @ApiOperation("自定义sql分页查询（mapper.xml, 适合多表查询）")
    @GetMapping(value = "/myPage")
    @ResponseBody
    public Result myPage(@ModelAttribute TmptBaseFileBizDto tmptBaseFileBizDto, String userDetailsJson){
        UserDetailsDto userDetailsDto = UserDetailsDto.getUserDetailsDto(userDetailsJson, "tmptBaseFile:query");
        return super.myPage(tmptBaseFileBizDto, userDetailsDto);
    }


    @PreAuthorize("hasAuthority('tmptBaseFile:query')")
    @ApiOperation("查询所有")
    @GetMapping(value = "/selectBy")
    @ResponseBody
    public Result selectBy(@ModelAttribute TmptBaseFileBizDto tmptBaseFileBizDto, String userDetailsJson){
        UserDetailsDto userDetailsDto = UserDetailsDto.getUserDetailsDto(userDetailsJson, "tmptBaseFile:query");
        return super.selectBy(tmptBaseFileBizDto, userDetailsDto);
    }


    @PreAuthorize("hasAuthority('tmptBaseFile:query')")
    @ApiOperation("selectById")
    @GetMapping(value = "/selectById")
    @ResponseBody
    public Result selectById(Long id){
        return super.selectById(id);
    }


    @PreAuthorize("hasAuthority('tmptBaseFile:query')")
    @ApiOperation("SQL动态多选项, spring动态调用")
    @GetMapping(value = "/select4column")
    @ResponseBody
    public Result select4column(String columnName){
        return super.select4column(columnName);
    }

    @PreAuthorize("hasAuthority('tmptBaseFile:create')")
    @ApiOperation("新增对象")
    @PostMapping(value = "/create")
    @ResponseBody
    public Result create(@RequestBody TmptBaseFileBizDto tmptBaseFileBizDto,
                    String _userId, String _userName, String _companyId){
        return super.create(tmptBaseFileBizDto, _userId, _userName, _companyId);
    }


    @PreAuthorize("hasAuthority('tmptBaseFile:update')")
    @ApiOperation("编辑对象")
    @PostMapping(value = "/update")
    @ResponseBody
    public Result update(@RequestBody TmptBaseFileBizDto tmptBaseFileBizDto,
                        String _userId, String _userName){
        return super.update(tmptBaseFileBizDto, _userId, _userName);
    }


    @PreAuthorize("hasAuthority('tmptBaseFile:delete')")
    @ApiOperation("逻辑删除对象，由deleteflag控制：0:有效，1:已删除。")
    @PostMapping(value = "/delete")
    @ResponseBody
    public Result delete(Long id, String _userId, String _userName){
        return super.delete(id, _userId, _userName);
    }


    @PreAuthorize("hasAuthority('tmptBaseFile:deletePhysical')")
    @ApiOperation("物理删除对象，默认注释了核心调用方法，请按需启用")
    @PostMapping(value = "/deletePhysical")
    @ResponseBody
    public Result deletePhysical(Long id){
        return super.deletePhysical(id);
    }


//    @PreAuthorize("hasAuthority('tmptBaseFile:deletePhysical')")
    @ApiOperation("删除历史文件")
    @PostMapping(value = "/deleteHisFile")
    @ResponseBody
    public Result deleteHisFile(Map<String,String> type){
        return tmptBaseFileBizService.deleteHisFile(type);
    }

}
